package com.zmn.oms.model.entity.perf;

import com.zmn.common.utils.date.DateUtil;
import com.zmn.common.utils.pager.Pages;
import com.zmn.mcc.common.enums.DpermitEnum;
import com.zmn.mcc.permit.client.annotation.PermitDataType;
import lombok.Data;
import lombok.EqualsAndHashCode;
import org.springframework.format.annotation.DateTimeFormat;

import javax.validation.constraints.NotNull;
import java.io.Serializable;
import java.time.LocalDate;
import java.time.format.DateTimeFormatter;
import java.util.List;
import java.util.Optional;

/**
 * 派单绩效报表查询对象
 *
 * @author hankangshuai
 * @since 2019-09-23 14:11:44
 */
@EqualsAndHashCode(callSuper = true)
@Data
public class PerfDimensionDistributeQuery extends Pages implements PerfTimeQuery, Serializable {

    private static final long serialVersionUID = -66191284471218796L;

    /**
     * 主键-纬度id
     */
    Integer dimensionId;

    /**
     * 平台ID
     */
    private List<Integer> plat;

    /**
     * 部门ID
     */
    Integer deptId;

    /**
     * 派单员ID
     */
    Integer distributorId;

    /**
     * 数据权限：平台
     */
    @PermitDataType(value = DpermitEnum.ORGANIZE_PLAT)
    private List<Integer> permitPlatIdList;

    /**
     * 查询起始日期
     */
    @NotNull(message = "起始时间不能为空")
    @DateTimeFormat(iso = DateTimeFormat.ISO.DATE)
    LocalDate from;

    /**
     * 查询结束日期
     */
    @NotNull(message = "结束时间不能为空")
    @DateTimeFormat(iso = DateTimeFormat.ISO.DATE)
    LocalDate to;

    @Override
    public Integer getFrom() {
        return Optional.ofNullable(this.from).map(localDate -> {
            String format = localDate.format(DateTimeFormatter.ofPattern(DateUtil.FORMAT_DATE2));
            return Integer.parseInt(format);
        }).orElse(null);
    }

    @Override
    public Integer getTo() {
        return Optional.ofNullable(this.to).map(localDate -> {
            String format = localDate.format(DateTimeFormatter.ofPattern(DateUtil.FORMAT_DATE2));
            return Integer.parseInt(format);
        }).orElse(null);
    }
}